import wepy from '@wepy/core';

const baseUrl = "http://ytmedia.3322.org:19102/analysis"

export const request = (url, params, method) => {
  return new Promise((resolve, reject) => {

    wx.request({
      url: `${baseUrl}${url}`, //开发者服务器接口地址",
      data: params ? params : {}, //请求的参数",
      method: method ? method : 'GET',
      header: {
        'content-type': 'application/json', // 默认值
        'token': 'token' // token
      },
      dataType: "json",
      // 成功执行
      success: res => {
        // 成功了
        console.log("成功了")
        resolve(res)
      },
      // 出错执行
      fail: () => {
        // 失败了
        console.log("失败了")
        reject()
      },
      // 成功,出错都会执行
      complete: () => {
        console.log("complete")
      }
    })

  });
}

export const GET = (data) => {
  return request(data.url, data.params, "GET");
}

export const POST = (data) => {
  return request(data.url, data.params, "POST");
}

const HTTP = {
  GET: GET,
  POST: POST,
  request: request,
}

export default HTTP
